<template>
  <div class="unique-tools-container">
    <el-card class="tools-card">
      <template #header>
        <div class="card-header">
          <span>独有工具列表</span>
          <el-button type="primary" @click="refreshTools">刷新</el-button>
        </div>
      </template>
      <el-table :data="uniqueTools" style="width: 100%">
        <el-table-column prop="id" label="ID" width="120" align="center" />
        <el-table-column prop="name" label="名称" width="150" align="center" />
        <el-table-column prop="description" label="描述" min-width="200" />
        <el-table-column label="图标" width="100" align="center">
          <template #default="{ row }">
            <el-icon><component :is="row.icon"></component></el-icon>
          </template>
        </el-table-column>
        <el-table-column label="类型" width="120" align="center">
          <template #default="{ row }">
            <el-tag :type="getTagType(row.type)">{{ row.type || '未定义' }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

interface UniqueTool {
  id: string
  name: string
  description: string
  icon: string
  type?: string
}

const uniqueTools = ref<UniqueTool[]>([])

const fetchUniqueTools = async () => {
  try {
    const response = await fetch('/api/agents/tools/commonTools')
    if (!response.ok) {
      throw new Error('Network response was not ok')
    }
    const data = await response.json()
    uniqueTools.value = data.unique_tools || []
  } catch (error) {
    console.error('Failed to fetch unique tools:', error)
    ElMessage.error('获取独有工具列表失败')
  }
}

const refreshTools = () => {
  fetchUniqueTools()
}

const getTagType = (type: string | undefined) => {
  if (!type) return 'info'
  switch (type.toLowerCase()) {
    case 'input':
      return 'success'
    case 'process':
      return 'warning'
    case 'output':
      return 'danger'
    default:
      return 'info'
  }
}

onMounted(() => {
  fetchUniqueTools()
})
</script>

<style scoped>
.unique-tools-container {
  padding: 20px;
}

.tools-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 